<?php
namespace App\Http\Controllers\Admin;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Request;

class GeographicController extends Controller
{
    use ApiResponse;

    public function getList(Request $request){
        try{
            $url = 'https://wx.suofeiya.com.cn/new/api/region/getTreeList';
            $response = (new \GuzzleHttp\Client())->request('GET', $url, ['verify'  =>  false]);
            $result = [];
            if ($response->getStatusCode() == 200) {
                $result = json_decode($response->getBody(), true);
            }
            if (empty($result)){
                throw new \Exception('获取失败');
            }
            if ($result['code'] !=0){
                throw new \Exception($result['message'] ?? '获取失败');
            }
            return $this->success('获取成功', $result['data'] ?? []);
        }catch (\Exception $e){
            return $this->error($e->getMessage() ?: '获取错误');
        }
    }
}
